const fs = require('fs')

const jwt = require('jsonwebtoken')
class AuthController {
  async login(ctx, next) {
    const {id,rid,username,mobile,email} = ctx.user
    const privateKey = fs.readFileSync('src/app/keys/private.key')
    const token = jwt.sign({
      id,
      username
    }, privateKey, {
      expiresIn: 60 * 60 * 24,
      algorithm:'RS256'
    })
    ctx.body = {
      data: {
        id,
        rid,
        username,
        mobile,
        email,
        token
      },
      meta: {
        msg: '登录成功',
        status:200
      }
    }
  }
}
module.exports = new AuthController()